import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;


public class XMenuBar {

    public static JMenuBar createMenuBar(){
        JMenuBar menuBar = new JMenuBar();
        JMenu fileMenu = new JMenu("书籍维护");
        JMenu editMenu = new JMenu("楼层维护");
        JMenu aboutMenu = new JMenu("值班人员");
        JMenu ssxMenu = new JMenu("图书租借");

        //create menu items
        JMenuItem newMenuItem = new JMenuItem("采购需求");

        JMenuItem cutMenuItem = new JMenuItem("Cut");

        JMenuItem copyMenuItem = new JMenuItem("Copy");

        fileMenu.add(newMenuItem);

        editMenu.add(cutMenuItem);
        editMenu.add(copyMenuItem);

        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(aboutMenu);


        return menuBar;
    }

    public static JToolBar createJToolBar(JPanel contentPanel,Box box){
        JToolBar toolBar = new JToolBar("工具栏");



        XButton buttonA = new XButton("首页(H)",ImageIconUtil.createImageIcon("images/home.png"));
        XButton buttonB = new XButton("新建(N)",ImageIconUtil.createImageIcon("images/chuangjian.png"));
        XButton buttonC = new XButton("保存(S)",ImageIconUtil.createImageIcon("images/baocun.png"));
        XButton buttonE = new XButton("取消(C)",ImageIconUtil.createImageIcon("images/chexiao.png"));
        XButton buttonD = new XButton("审核(P)",ImageIconUtil.createImageIcon("images/shenhe.png"));
        XButton buttonF = new XButton("帮助(M)",ImageIconUtil.createImageIcon("images/bangzhu.png"));
        XButton buttonJ = new XButton("查询(F)",ImageIconUtil.createImageIcon("images/chaxun.png"));

        XInput xInput = new XInput(5);
        xInput.setSize(100,32);
        xInput.setBorder(BorderFactory.createEmptyBorder());
        toolBar.add(buttonA);
        toolBar.add(buttonB);
        toolBar.add(buttonC);
        toolBar.add(buttonD);
        toolBar.add(buttonE);
        toolBar.add(buttonJ);
        toolBar.add(buttonF);

        buttonA.addActionListener(e -> {
            SwingUtilities.invokeLater(() -> {
                JPanel panel6 = new JPanel() {
                    public void paintComponent(Graphics g) {
                        ImageIcon icon = ImageIconUtil.createImageIcon("images/bg.jpg");
                        g.drawImage(icon.getImage(), 0, 0, icon.getIconWidth(),icon.getIconHeight(),contentPanel);
                    }
                };

                contentPanel.remove(box);
                contentPanel.add(panel6,BorderLayout.CENTER);
                contentPanel.updateUI();
            });
            new Thread(new Runnable() {
                @Override
                public void run() {


                }
            }).start();

        });

        toolBar.setFloatable(false);

        toolBar.setBorder(BorderFactory.createEmptyBorder());
        toolBar.setForeground(Color.BLUE);

        return toolBar;
    }




}
